package crm.model.studentPC.win.window;

import java.awt.Rectangle;


import com.sun.jna.platform.win32.WinDef.HWND;
import com.sun.jna.platform.win32.WinDef.RECT;

public class Window {
    public static int SW_HIDE = 0;
    public static int SW_SHOWNORMAL = 1;
    public static int SW_SHOWMINIMIZED = 2;
    public static int SW_SHOWMAXIMIZED = 3;
    public static int SW_SHOWNOACTIVATE = 4;
    public static int SW_RESTORE = 9;
    public static int SW_SHOWDEFAULT = 10;


	String name;
	Rectangle rectangle;
	HWND hwnd;
	User32B user32;
	public Window(HWND hwnd, User32B user32){
		this.hwnd = hwnd;
		this.user32 = user32;


		char[] name = new char[user32.GetWindowTextLengthA(hwnd)+1];
		user32.GetWindowText(hwnd, name, name.length);
		String strName = new String(name);
		strName = strName.substring(0, strName.length()-1);
		setName(strName);
		RECT r = new RECT();
		user32.GetWindowRect(hwnd, r);
		Rectangle rec = r.toRectangle();
		setRectangle(rec);
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Rectangle getRectangle() {
		return rectangle;
	}

	public void setRectangle(Rectangle rectangle) {
		this.rectangle = rectangle;
	}
	public void hide(){
		user32.ShowWindowAsync(hwnd, Window.SW_HIDE);

	}
	public void maximized(){
		user32.ShowWindowAsync(hwnd, Window.SW_SHOWMAXIMIZED);

	}
	public void minimized(){
		user32.ShowWindowAsync(hwnd, Window.SW_SHOWMINIMIZED);
	}
	public void restore(){
		user32.ShowWindowAsync(hwnd, Window.SW_RESTORE);
	}
	public void kill(){
		user32.DestroyWindow(hwnd);
	}

	public boolean isVisible(){
		return user32.IsWindowVisible(hwnd);
	}
	public boolean endTask(boolean force){
		return user32.EndTask(hwnd, true, force);
	}
}












